package com.ocom.oauth.auth.xcx;

import com.ocom.oauth.auth.CustomAbstractTokenGranter;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.oauth2.provider.ClientDetailsService;
import org.springframework.security.oauth2.provider.OAuth2RequestFactory;
import org.springframework.security.oauth2.provider.token.AuthorizationServerTokenServices;

import java.util.Map;

/**
 *
 *  说明：
 *    验证码
 *    定义验证码具体逻辑
 */
public class XcxTokenGranter extends CustomAbstractTokenGranter {

    private static final String CODE_AUTH = "wx_login";

    private XcxUserDetailService xcxUserDetailService;

    public XcxTokenGranter(AuthorizationServerTokenServices tokenServices, ClientDetailsService clientDetailsService, OAuth2RequestFactory requestFactory, XcxUserDetailService xcxUserDetailService) {
        super(tokenServices, clientDetailsService, requestFactory, CODE_AUTH);
        this.xcxUserDetailService = xcxUserDetailService;
    }

    @Override
    protected UserDetails getUserDetails(Map<String, String> parameters) {
        String wx_code = parameters.get("wx_code");
        String comId = parameters.get("com_id");
        return xcxUserDetailService.loadByCode(wx_code,comId);
    }
}

